<!--
 * @Author: your name
 * @Date: 2020-12-03 15:52:30
 * @LastEditTime: 2021-01-26 19:23:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\inventory\inventory_push.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('inventoryManage.stockTitle')"
        :visible="newVisibleFlow"
        width="700px"
        @close="()=>{$store.commit('setNewVisibleFlow',false)}"
        :close-on-click-modal='false'
        >   
            <el-row :gutter="20">
                <el-col :span="19" :offset="2">
                    <el-form ref="form" :model="form" label-width="160px" >
                        <el-form-item :label="$t('version.versionService.fileURL')" prop="file" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <baseFile v-model="form.file" style="width:100%"  >
                            </baseFile>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="19" :offset="4">
                    <el-button type="primary" @click="downloadModal('form')">{{$t('download.templates')}}</el-button>
                    <span style="color:red;">{{$t('inventoryManage.pushMsg')}}</span>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisibleFlow',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseFile from '../../components/common/baseFileInput'
export default {
    components: {
        baseFile
    },
    props: {
        getUserTypeFlag:{
            type:String,
            default:''
        }
    },
    data() {
        return {
            form:{
                file:''
            },
        };
    },
    computed: {
        newVisibleFlow(){
            return this.$store.state.sysStore.newVisibleFlow
        },
        userType(){
            return localStorage.getItem('userType')
        },
        lan(){
            return localStorage.getItem('lan')
        },
    },
    watch: {

    },
    created() {

    },
    mounted() {
    },
    methods: {
        downloadModal(){
            if(this.getUserTypeFlag == '0'){
                window.open(process.env.VUE_APP_DOWNLOAD_PROXY+'/resource/files/warehouseManagement/deliveryRecordTemplate.xlsx')
            }else{
                this.comm.windowOpen('/wmsstock/downloadTemplate')
            }
        },
        async wmsstockImportGoods(){
            let res = await this.API.wmsstockImportGoods({
                file:this.form.file,
            })
            if(!res.success){
                this.comm.showMsg(false)
            }else{
                if(res.object&&res.object.repeatSnList.length>0){
                    this.comm.showMsg(false,`$t('inventoryManage.pushErroy1')${JSON.stringify(res.object.repeatSnList)}`)
                    this.$store.commit('setNewVisibleFlow',false)
                    this.$emit('uploadData',true)
                }else{
                    this.$store.commit('setNewVisibleFlow',false)
                    this.$emit('uploadData',true)
                }
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.wmsstockImportGoods()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" scoped>

</style>
